<?php
/**
 * 京粉精选商品查询接口 jd.union.open.goods.jingfen.query
 *
 * See: https://union.jd.com/openplatform/api/739
 * User: Ken.Zhang <kenphp@yeah.net>
 * Date: 2019-05-12
 */
class UnionOpenGoodsJingfenQueryRequest {

    /**
     * 频道id：
     * 1-好券商品,
     * 2-京粉APP-jingdong.大咖推荐,
     * 3-小程序-jingdong.好券商品,
     * 4-京粉APP-jingdong.主题街1-jingdong.服装运动,
     * 5-京粉APP-jingdong.主题街2-jingdong.精选家电,
     * 6-京粉APP-jingdong.主题街3-jingdong.超市,
     * 7-京粉APP-jingdong.主题街4-jingdong.居家生活,
     * 10-9.9专区,11-品牌好货-jingdong.潮流范儿,
     * 12-品牌好货-jingdong.精致生活,
     * 13-品牌好货-jingdong.数码先锋,
     * 14-品牌好货-jingdong.品质家电,
     * 15-京仓配送,
     * 16-公众号-jingdong.好券商品,
     * 17-公众号-jingdong.9.9,
     * 18-公众号-jingdong.京仓京配
     */
    private $eliteId;

    /**
     * 页码
     */
    private $pageIndex;

    /**
     * 每页数量，默认20，上限50
     */
    private $pageSize;

    /**
     * 排序字段
     * price：单价,
     * commissionShare：佣金比例,
     * commission：佣金，
     * inOrderCount30DaysSku：sku维度30天引单量，
     * comments：评论数，
     * goodComments：好评数
     */
    private $sortName;

    /**
     * asc,desc升降序,默认降序
     */
    private $sort;

    /**
     * 请求参数
     */
    public $apiParams = [];

    public function setEliteId($elite_id)
    {
        $this->eliteId = $elite_id;
        $this->apiParams['goodsReq']['eliteId'] = $elite_id;
    }

    public function getEliteId()
    {
        return $this->eliteId;
    }

    public function setPageIndex($page_index)
    {
        $this->pageIndex = $page_index;
        $this->apiParams['goodsReq']['pageIndex'] = $page_index;
    }

    public function getPageIndex()
    {
        return $this->pageIndex;
    }

    public function setPageSize($page_size)
    {
        $this->pageSize = $page_size;
        $this->apiParams['goodsReq']['pageSize'] = $page_size;
    }

    public function getPageSize()
    {
        return $this->pageSize;
    }

    public function setSortName($sort_name)
    {
        $this->sortName = $sort_name;
        $this->apiParams['goodsReq']['sortName'] = $sort_name;
    }

    public function getSortName()
    {
        return $this->sortName;
    }

    public function setSort($sort)
    {
        $this->sort = $sort;
        $this->apiParams['goodsReq']['sort'] = $sort;
    }

    public function getSort()
    {
        return $this->sort;
    }

    public function getApiMethodName()
    {
        return 'jd.union.open.goods.jingfen.query';
    }

    /**
     * 解析结果
     *
     * @param   string      $response
     * @throws  Exception
     * @return  mixed
     */
    public function getResult($response)
    {
        $responseKey = str_replace('.', '_', $this->getApiMethodName()) . '_response';

        $response = @json_decode($response, true);
        if (!array_key_exists($responseKey, $response))
            $resp = $response['errorResponse'];
        else {
            $response[$responseKey]['result'] = json_decode($response[$responseKey]['result']);

            $resp = $response[$responseKey];
        }

        return $resp;
    }

}